package com.atguigu.JVMDay02;

import java.util.concurrent.TimeUnit;

//强引用
public class StrongReferenceTest {
    public static void main(String[] args) {
        User user1 = new User(19,"yyqx");
        User use2 = user1;

        // 把user1置为空，User对象不会被回收，因为还在被引用
        user1=null;
        System.out.println(use2);
        System.gc();

        //线程睡眠几秒
        try {
            TimeUnit.SECONDS.sleep(1);} catch (InterruptedException e) {throw new RuntimeException(e);}

        System.out.println(use2);
    }
}
class User{
    Integer age;
    String name;

    public  User(Integer age,String name){
        this.age=age;
        this.name=name;
    }



    @Override
    public String toString() {
        return "User{" +
                "age=" + age +
                ", name='" + name + '\'' +
                '}';
    }
}
